home *** CD-ROM | disk | FTP | other *** search
- 10 'INANDOUT.BAS - program to illustrate the use of input and output using
- 20 'disk and printer devices
- 30 'Program written by Richard Harper and modified by (Your name here!)
- 40 'From the GW-BASIC tutorial series, file GWBT03 08/15/1990
- 50 '
- 60 'For this demonstration, we will be using the following variables and
- 70 'devices:
- 80 ' TEXTFILE.TXT is our disk file
- 90 ' LINEOFDATA$ is the string variable that we will use
- 100 ' for input and output
- 110 ' LPT1: is the printer. Please note that if your
- 120 ' printer is attached to the second parallel
- 130 ' port (LPT2:), you will need to change all of
- 140 ' the LPT1: device names to LPT2:
- 150 '
- 160 'If you have no printer, change the LPT1: device name to SCRN: instead
- 170 'so that all lines will print on your screen.
- 180 'Start of main program:
- 190 CLS
- 200 PRINT "We are going to demonstrate use of disk files and printer input
- 210 PRINT "and output. Please type in several lines, pressing ENTER at"
- 220 PRINT "the end of each line, and press ENTER alone on a new line to quit"
- 230 PRINT "entering lines and to see the remainer of the demonstration."
- 240 PRINT
- 250 'This next line opens the TEXTFILE.TXT file
- 260 OPEN "TEXTFILE.TXT" FOR OUTPUT AS #1
- 270 LINE INPUT "Enter a line: ",LINEOFDATA$
- 280 IF LINEOFDATA$="" THEN GOTO 320
- 290 PRINT #1,LINEOFDATA$
- 300 GOTO 270
- 310 'The user has entered a blank line, so let's show what we have in the file
- 320 PRINT #1,LINEOFDATA$
- 330 CLOSE #1
- 340 'Notice that we CLOSE the file when we are done, so it can be used for
- 350 'INPUT below, and also so we can use the #1 device handle again
- 360 OPEN "TEXTFILE.TXT" FOR INPUT AS #1
- 370 OPEN "LPT1:" FOR OUTPUT AS #2
- 380 LINE INPUT #1,LINEOFDATA$
- 390 IF LINEOFDATA$="" THEN GOTO 430
- 400 PRINT #2,LINEOFDATA$
- 410 GOTO 380
- 420 'All done, so close all devices and end the program
- 430 CLOSE #1
- 440 CLOSE #2
- 450 END
- 460 'End of program - INANDOUT.BAS
-